﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Calvin.Utilities;
using System.Data;
using System.Data.Common;

namespace DbHelperTest
{
    class Program
    {

        public static DbHelper dbOp = new DbHelper(System.Configuration.ConfigurationManager.ConnectionStrings["dbName"].ConnectionString, System.Configuration.ConfigurationManager.ConnectionStrings["dbName"].ProviderName);
        static void getdaya()
        {
            DbConnection con = null;
            try
            {

                con = dbOp.GetConnection();
                Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());

                for (int i = 0; i < 20; i++)
                {
                    System.Threading.Thread.Sleep(10);
                    int p = dbOp.ExecuteNonQuery("select * from EMP t", CommandType.Text, con);
                    Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + p.ToString());
                }

            }
            catch (Exception e)
            {
                System.IO.File.AppendAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt"), e.Message + e.Source);

            }
            finally
            {

                con.Close();
                con.Dispose();
                con = null;
            }

        }
        
        static void Main(string[] args)
        {
            try
            {

                //DbHelper dbOp = new DbHelper(System.Configuration.ConfigurationManager.ConnectionStrings["dbName"].ConnectionString, System.Configuration.ConfigurationManager.ConnectionStrings["dbName"].ProviderName);
                DataTable table = DbProviderFactories.GetFactoryClasses();
                DbConnection con = dbOp.GetConnection();
                for (int i = 0; i < 2; i++)
                {
                    System.Threading.Thread s = new System.Threading.Thread(new System.Threading.ThreadStart(getdaya));
                    s.Start();

                }
            }
            catch (Exception e)
            {
                System.IO.File.AppendAllText(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt"), e.Message + e.Source);
            
            }
            Console.Read();
        }
    }
}
